import static java.lang.Thread.sleep;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-08-10
 * Time: 20:37
 * To BE A Better Person-2020-3-2
 */
public class TestDemo2 {
    public static Object locker=new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            synchronized (locker){
                for (int i = 0; i < 3; i++) {
                    try {
                        System.out.println("我是线程1");
                        sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        Thread t2=new Thread(()->{
            synchronized (locker){
                for (int i = 0; i < 3; i++) {
                    try {
                        System.out.println("我是线程2");
                        sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        t1.start();
        t2.start();
        sleep(500);
        System.out.println("t2 state>"+t2.getState());


    }
}
